//
//  StatusCellTopView.swift
//  Weibo
//
//  Created by 孙明海 on 16/1/27.
//  Copyright © 2016年 孙明海. All rights reserved.
//

import UIKit


class StatusCellTopView: UIView {
    /// 微博视图模型
    var statusViewModel: StatusViewModel? {
        didSet {
             iconView.sd_setImageWithURL(statusViewModel?.userIconImageURL, placeholderImage: UIImage(named: "avatar_default_big"))
            memberIconView.image = statusViewModel?.userMemberImage
            nameLable.text = statusViewModel?.userName
            vipIconView.image = statusViewModel?.userVipImage
            timeLable.text = statusViewModel?.status.dateTime
            sourceLable.text = statusViewModel?.status.source
        }
    }

    /// 构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK: - 懒加载控件
    /// 图像
    private lazy var iconView: UIImageView = UIImageView(imageName: "avatar_default_big")
    /// 姓名
    private lazy var nameLable: UILabel = UILabel(title: "我的微博", fontSize: 14)
    /// 会员图标
    private lazy var memberIconView: UIImageView = UIImageView(imageName: "avatar_enterprise_vip")
    /// vip图标
    private lazy var vipIconView: UIImageView = UIImageView(imageName: "common_icon_membership_level1")
    //时间标签
    private lazy var timeLable: UILabel = UILabel(title: "现在", fontSize: 11, color: UIColor.orangeColor())
    /// 来源标签
    private lazy var sourceLable: UILabel = UILabel(title: "来源", fontSize: 11)
}
// MARK: - 设置界面
extension StatusCellTopView {
    private func setupUI() {
        
        //增加分隔视图
        let sepView = UIView()
        sepView.backgroundColor = UIColor.darkGrayColor()
        addSubview(sepView)
        
        //添加子控件
        addSubview(iconView)
        addSubview(memberIconView)
        addSubview(nameLable)
        addSubview(vipIconView)
        addSubview(timeLable)
        addSubview(sourceLable)
        
        //设置约束
        sepView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.right.equalTo(self.snp_right)
            make.height.equalTo(StatusCellMargin)
        }
        
        iconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(StatusCellMargin)
            make.top.equalTo(sepView.snp_bottom).offset(StatusCellMargin)
            make.width.equalTo(StatusCellIconWidth)
            make.height.equalTo(StatusCellIconWidth)
        }
        memberIconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_right)
            make.centerY.equalTo(iconView.snp_bottom)
        }
        nameLable.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
            make.top.equalTo(iconView.snp_top)
        }
        vipIconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(nameLable.snp_top)
            make.left.equalTo(nameLable.snp_right).offset(StatusCellMargin)
        }
        timeLable.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(iconView.snp_bottom)
            make.left.equalTo(nameLable.snp_left)
        }
        sourceLable.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(iconView.snp_bottom)
            make.left.equalTo(timeLable.snp_right).offset(StatusCellMargin)
        }
    }
}
